#!/usr/bin/env python

import wsgiref.handlers

from google.appengine.ext import webapp

from entities import document

class SaveHandler(webapp.RequestHandler):
    def get(self):
        document_id = self.request.get("document_id")
        if(document_id != ''):
            doc = document.Document.get_by_id(int(document_id))
            if ( doc ):
                documentName = document_id+".txt"
                self.response.headers['Content-Type'] = "text/plain"
                self.response.headers['Content-Disposition'] = "attachment; filename="+str(documentName)

                self.response.out.write(doc.documentContent)
